package com.generator.one;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.Context;
import org.mybatis.generator.config.TableConfiguration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
public class OneApplication {

/*    public static void main(String[] args) {
        SpringApplication.run(OneApplication.class, args);
    }*/

    public static void main(String[] args) throws Exception{
        List<String> warnings = new ArrayList<>();
        File configFile = new File("src/main/resources/generatorConfig.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(configFile);
        List<Context> contexts = config.getContexts();
        Context context = contexts.get(0);
        List<TableConfiguration> tableConfigurations = context.getTableConfigurations();
        tableConfigurations.forEach(x->{
            x.setCountByExampleStatementEnabled(false);
            x.setDeleteByExampleStatementEnabled(false);
            x.setSelectByExampleStatementEnabled(false);
            x.setUpdateByExampleStatementEnabled(false);
            x.setSelectByExampleQueryId("false");
        });
        DefaultShellCallback callback = new DefaultShellCallback(Boolean.TRUE);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,callback, warnings);
        myBatisGenerator.generate(null);
    }
}
